#include<bits/c++.h>
using namespace std;

int a[100005],d[100005],v[100005],p[100005];

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,n,m,l,v;
    cin>>t;
    cout<<endl;
    for(int i=0;i<t;i++)
    {
        cin>>n>>m>>l>>v;
        for(int j=0;j<n;j++)
        {
            cin>>d[j]>>v[j]>>a[j];
        }
        if(int j=0;j<m;j++)
            cin>>p[j];
        cout<<v<<" "<<v<<endl;
    }
    return 0;
}
